package org.one.stone.soup.db.indexing;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.one.stone.soup.db.processors.JSON;

public class KeyValueIndex implements Index{

	private Map<String,Long> map;
	
	public void index(long id,String key) {
		map.put(key,id);
	}
	
	public long findMatch(String key) {
		return map.get(key);
	}
	
	public Long[] findMatches(String regex) {
		List<Long> result = new ArrayList<Long>();
		for(String key: map.keySet()) {
			if(key.matches(regex)) {
				result.add( map.get(key) );
			}
		}
		
		return result.toArray(new Long[]{});
	}

	public void index(long index, JSON json) {
		index( index,json.getName() );
	}
}
